<template>
  <div>
    <div class="emp-header">
      <div class="emp-header-left">
        <el-input v-model="empName"
                  style="width: 300px; margin: 8px 8px"
                  prefix-icon="el-icon-search"
                  placeholder="根据员工姓名查询员工..."
                  clearable
                  @clear="initEmps"
                  @keydown.enter.native="initEmps"></el-input>
        <el-button size="small" type="primary" icon="el-icon-search" @click="initEmps">搜索</el-button>
        <el-button size="small" type="primary" @click="showAdvanceSearchVisible = !showAdvanceSearchVisible">
          <i :class="showAdvanceSearchVisible?'fa fa-angle-double-up':'fa fa-angle-double-down'" aria-hidden="true" ></i>
          高级搜索
        </el-button>
      </div>
      <div class="emp-header-right">

        <el-upload
            style="display: inline-flex;margin-right: 8px"
            action="/api/excel/import"
            name="name"
            :headers="headers"
            :show-file-list="false"
            :before-upload="beforeUpload"
            :on-success="onSuccess"
            :on-error="onError"
            :disabled="disabledUpload">
          <el-button type="success" :icon="importButtonIcon" :disabled="disabledUpload">
            {{ importButtonText }}
          </el-button>
        </el-upload>

        <el-button type="success" @click="exportFile" icon="el-icon-download">
          导出数据
        </el-button>
        <el-button type="primary" icon="el-icon-plus" @click="showAddEmpView">添加员工</el-button>
      </div>
    </div>
    <transition name="bounce">
      <div v-show="showAdvanceSearchVisible" style="border: 1px solid #409eff; border-radius: 5px;box-sizing: border-box;padding: 5px;margin: 10px 0">
      <el-row>
        <el-col span="5">
          政治面貌：
            <el-select v-model="searchVisible.politicId" filterable placeholder="政治面貌" style="width: 150px">
              <el-option
                  v-for="item in politicsState"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
              </el-option>
            </el-select>
        </el-col>
        <el-col span="4">
          民族:
          <el-select v-model="searchVisible.nationId"  placeholder="民族" filterable style="width: 110px">
            <el-option
                v-for="item in nations"
                :key=" item.id "
                :label=" item.name "
                :value=" item.id ">
            </el-option>
          </el-select>
        </el-col>
        <el-col span="4">
          职位:
          <el-select v-model="searchVisible.posId" placeholder="职位" style="width: 110px">
            <el-option
                v-for="item in position"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-col>
        <el-col span="4">
          职称:
          <el-select v-model="searchVisible.jobLevelId" placeholder="职称" style="width: 110px">
            <el-option
                v-for="item in jobLevels"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-col>
        <el-col span="5">
          聘用形式:
          <el-radio-group v-model="searchVisible.engageForm" style="margin: 8px 0">
            <el-radio label="劳动合同">劳动合同</el-radio>
            <el-radio label="劳务合同">劳务合同</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
      <el-row>
        <el-col span="5" >
          所属部门：
          <el-button @click="selectDep2"
                     style="width: 150px;height: 30px; margin: 8px 0 "
                     prefix-icon="el-icon-edit">
            {{ departmentName }}
          </el-button>
          <el-popover
              placement="right"
              title="选择部门"
              width="200"
              trigger="click"
              v-model="visible2"
          >
            <el-tree :data="allDeps"
                     :props="defaultProps"
                     default-expand-all
                     @node-click="searchHandleNodeClick"
            ></el-tree>
          </el-popover>
        </el-col>
        <el-col span="8">
          入职日期：
          <div style="display: inline-flex; margin: 8px 0">
            <el-date-picker
                v-model="searchVisible.beginDateScope"
                type="daterange"
                align="right"
                format="yyyy-MM-dd"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                >
            </el-date-picker>
          </div>
        </el-col>
        <el-col span="4" :offset="6">
          <el-button size="small" style="margin: 8px 4px" @click="cancelSearch">取消</el-button>
          <el-button size="small" type="primary" icon="el-icon-search" style="margin: 8px 4px" @click="initEmps('advance')">搜索</el-button>
        </el-col>
      </el-row>
      </div>
    </transition>
    <div>
      <el-table
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
          :data="emps"
          stripe
          border
          style="width: 100%">
        <el-table-column
            type="selection"
            width="40">
        </el-table-column>
        <el-table-column
            prop="name"
            label="姓名"
            fixed="left"
            align="left"
            width="60">
        </el-table-column>
        <el-table-column
            prop="workID"
            label="工号"
            align="left"
            width="85">
        </el-table-column>
        <el-table-column
            prop="gender"
            label="性别"
            align="left"
            width="85">
        </el-table-column>
        <el-table-column
            prop="birthday"
            label="出生日期"
            align="left"
            width="95">
        </el-table-column>
        <el-table-column
            prop="idCard"
            label="身份证号"
            align="left"
            width="150">
        </el-table-column>
        <el-table-column
            prop="wedlock"
            label="婚姻状况"
            align="left"
            width="50">
        </el-table-column>
        <el-table-column
            prop="nation.name"
            label="名族"
            align="left"
            width="50">
        </el-table-column>
        <el-table-column
            prop="nativePlace"
            label="籍贯"
            align="left"
            width="85">
        </el-table-column>
        <el-table-column
            prop="politicsStatus.name"
            label="政治面貌"
            align="left"
            width="95">
        </el-table-column>
        <el-table-column
            prop="email"
            label="电子邮件"
            align="left"
            width="150">
        </el-table-column>
        <el-table-column
            prop="phone"
            label="电话号码"
            align="left"
            width="100">
        </el-table-column>
        <el-table-column
            prop="address"
            label="联系地址"
            align="left"
            width="220">
        </el-table-column>
        <el-table-column
            prop="department.name"
            label="所属部门"
            align="left"
            width="85">
        </el-table-column>
        <el-table-column
            prop="joblevel.name"
            label="职位"
            align="left"
            width="95">
        </el-table-column>
        <el-table-column
            prop="engageForm"
            label="聘用形式"
            align="left"
            width="75">
        </el-table-column>
        <el-table-column
            prop="tiptopDegree"
            label="最高学历"
            align="left"
            width="75">
        </el-table-column>
        <el-table-column
            prop="school"
            label="毕业院校"
            align="left"
            width="150">
        </el-table-column>
        <el-table-column
            prop="specialty"
            label="专业"
            align="left"
            width="150">
        </el-table-column>
        <el-table-column
            prop="workState"
            label="在职状态"
            align="left"
            width="85">
        </el-table-column>
        <el-table-column
            prop="beginDate"
            label="入职日期"
            align="left"
            width="100">
        </el-table-column>
        <el-table-column
            prop="conversionTime"
            label="转正日期"
            align="left"
            width="100">
        </el-table-column>
        <el-table-column
            prop="beginContract"
            label="合同起始日期"
            align="left"
            width="100">
        </el-table-column>
        <el-table-column
            prop="endContract"
            label="合同截止日期"
            align="left"
            width="100">
        </el-table-column>
        <el-table-column
            label="合同期限"
            align="left"
            width="85">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.contractTerm }}</el-tag>
            年
          </template>
        </el-table-column>
        <el-table-column
            label="操作"
            align="left"
            fixed="right"
            width="180">
          <template slot-scope="scope">
            <el-button
                style="padding: 2px"
                size="mini"
                @click="handleEdit(scope.row)">编辑
            </el-button>
            <el-button
                style="padding: 2px"
                size="mini"
                type="primary"
                @click="">查看高级资料
            </el-button>
            <el-button
                style="padding: 2px"
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="display: flex;justify-content: flex-end">
      <el-pagination
          background
          @current-change="currentChange"
          @size-change="sizeChange"
          layout="sizes,prev, pager, next, jumper, ->, total"
          :total="total">
      </el-pagination>
    </div>
    <el-dialog
        :title="title"
        :visible.sync="dialogVisible"
        width="60%"
        :before-close="handleClose"
    >
      <div>
        <el-form :model="emp" ref="empForm" :rules="rules">
          <el-row>
            <el-col :span="6">
              <el-form-item label="姓名：" prop="name">
                <el-input style="width: 150px" v-model="emp.name" prefix-icon="el-icon-edit"
                          placeholder="输入名字.."></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="性别：" prop="gender">
                <el-radio-group v-model="emp.gender" style="margin: 8px 0">
                  <el-radio label="男">男</el-radio>
                  <el-radio label="女">女</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="出生日期：" prop="birthday">
                <div class="block">
                  <el-date-picker
                      style="width: 150px"
                      v-model="emp.birthday"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="出生日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="政治面貌：" prop="politicId">
                <el-select v-model="emp.politicId" filterable placeholder="请选择" style="width: 200px">
                  <el-option
                      v-for="item in politicsState"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="民族：" prop="nationId">
                <el-select v-model="emp.nationId" placeholder="民族" filterable style="width: 150px">
                  <el-option
                      v-for="item in nations"
                      :key=" item.id "
                      :label=" item.name "
                      :value=" item.id ">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="籍贯：" prop="nativePlace">
                <el-input style="width: 150px" v-model="emp.nativePlace" prefix-icon="el-icon-edit"
                          placeholder="输入籍贯.."></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话号码：" prop="phone">
                <el-input style="width: 150px" v-model="emp.phone" prefix-icon="el-icon-phone"
                          placeholder="输入电话号码.."></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="联系地址：" prop="address">
                <el-input style="width: 200px" v-model="emp.address" prefix-icon="el-icon-edit"
                          placeholder="输入联系地址.."></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="职位：" prop="posId">
                <el-select v-model="emp.posId" placeholder="职位" style="width: 150px">
                  <el-option
                      v-for="item in position"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="职称：" prop="jobLevelId">
                <el-select v-model="emp.jobLevelId" placeholder="职称" style="width: 150px">
                  <el-option
                      v-for="item in jobLevels"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属部门：" prop="departmentId">
                <el-button @click="selectDep"
                           style="width: 150px;height: 30px; margin-top: 2px"
                           prefix-icon="el-icon-edit">
                  {{ departmentName }}
                </el-button>
                <el-popover
                    placement="right"
                    title="选择部门"
                    width="200"
                    trigger="click"
                    v-model="visible"
                >
                  <el-tree :data="allDeps"
                           :props="defaultProps"
                           default-expand-all
                           @node-click="handleNodeClick"
                  ></el-tree>
                </el-popover>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="电子邮箱：" prop="email">
                <el-input style="width: 200px" v-model="emp.email" prefix-icon="el-icon-message"
                          placeholder="输入电子邮箱.."></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="工号：" prop="workID">
                <el-input disabled style="width: 150px" v-model="emp.workID" prefix-icon="el-icon-edit"
                          placeholder="输入工号.."></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="学历：" prop="tiptopDegree">
                <el-select v-model="emp.tiptopDegree" placeholder="学历" style="width: 150px">
                  <el-option
                      v-for="item in tiptopDegrees"
                      :key="item"
                      :label="item"
                      :value="item">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="毕业学校：" prop="school">
                <el-input style="width: 150px" v-model="emp.school" prefix-icon="el-icon-school"
                          placeholder="输入学校.."></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="专业名称：" prop="specialty">
                <el-input style="width: 200px" v-model="emp.specialty" prefix-icon="el-icon-edit"
                          placeholder="输入专业名称.."></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="入职日期：" prop="beginDate">
                <div class="block">
                  <el-date-picker
                      style="width: 150px"
                      v-model="emp.beginDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="入职日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="转正日期：" prop="conversionTime">
                <div class="block">
                  <el-date-picker
                      style="width: 130px"
                      v-model="emp.conversionTime"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="转正日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合同起始日期：" prop="beginContract">
                <div class="block">
                  <el-date-picker
                      style="width: 140px"
                      v-model="emp.beginContract"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="合同起始日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="合同截止日期：" prop="endContract">
                <div class="block">
                  <el-date-picker
                      style="width: 173px"
                      v-model="emp.endContract"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="合同截止日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="身份证号码：" prop="idCard">
                <el-input style="width: 200px" v-model="emp.idCard" prefix-icon="el-icon-edit"
                          placeholder="输入身份证号码.."></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="聘用形式：" prop="engageForm">
                <el-radio-group v-model="emp.engageForm" style="margin: 8px 0">
                  <el-radio label="劳动合同">劳动合同</el-radio>
                  <el-radio label="劳务合同">劳务合同</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="婚姻状况：" prop="wedlock">
                <el-radio-group v-model="emp.wedlock" style="margin: 8px 0">
                  <el-radio label="已婚">已婚</el-radio>
                  <el-radio label="未婚">未婚</el-radio>
                  <el-radio label="离异">离异</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

          </el-row>

        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="doAddEmp">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>
<script >
export default {
  name: "EmpBasic",
  data() {
    return {
      searchVisible:{
        politicId: null,
        nationId: null,
        posId: null,
        jobLevelId: null,
        engageForm: '',
        departmentId: null,
        beginDateScope:null
      },
      showAdvanceSearchVisible: false,
      headers:{
        Authorization:window.sessionStorage.getItem('tokenStr')
      },
      disabledUpload: false,
      importButtonText: '导入数据',
      importButtonIcon: 'el-icon-upload2',
      title: '',
      rules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'},
          {min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur'}
        ],
        birthday: [
          {required: true, message: '请选择出身日期', trigger: 'change'},
        ],
        nativePlace: [
          {required: true, message: '请输入籍贯', trigger: 'blur'},
        ],
        email: [
          {required: true, message: '请输入电子邮箱', trigger: 'blur'},
          {type: 'email', message: '邮箱格式不正确', trigger: 'blur'}
        ],
        address: [
          {required: true, message: '请输入联系地址', trigger: 'blur'},
        ],
        posId: [
          {required: true, message: '请选择职位', trigger: 'blur'},
        ],
        jobLevelId: [
          {required: true, message: '请选择职称', trigger: 'blur'},
        ],
        departmentId: [
          {required: true, message: '请选择部门', trigger: 'blur'},
        ],
        phone: [
          {required: true, message: '请输入电话号码', trigger: 'blur'},
          {pattern: /(^1[3|4|5|7|8][0-9]{9}$)|(^1[0-9]{10}$)/, message: '电话号码格式不正确', trigger: 'blur'}
        ],
        tiptopDegree: [
          {required: true, message: '请选择学历', trigger: 'blur'},
        ],
        school: [
          {required: true, message: '请输入毕业学校', trigger: 'blur'},
        ],
        specialty: [
          {required: true, message: '请输入所学专业', trigger: 'blur'},
        ],
        conversionTime: [
          {required: true, message: '请输入转正日期', trigger: 'blur'},
        ],
        endContract: [
          {required: true, message: '请输入合同终止日期', trigger: 'blur'},
        ],
        idCard: [
          {required: true, message: '请输入身份证号码', trigger: 'blur'},
          {
            pattern: /(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)|(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/,
            message: "身份证号码格式不正确", trigger: 'blur'
          }
        ],
        engageForm: [
          {required: true, message: '请选择合同模式', trigger: 'blur'},
        ],
      },
      visible: false,
      visible2: false,
      departmentName: '',
      allDeps: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      empName: '',
      emps: [],
      emp: {
        id: '',
        address: '',
        beginContract: '',
        beginDate: '',
        birthday: '',
        contractTerm: null,
        conversionTime: '',
        departmentId: null,
        email: '',
        endContract: '',
        engageForm: '',
        gender: '男',
        idCard: '',
        jobLevelId: null,
        name: '',
        nationId: 1,
        nativePlace: '',
        notWorkDate: null,
        phone: '',
        politicId: 13,
        posId: null,
        salaryId: null,
        school: '',
        specialty: '',
        tiptopDegree: '',
        wedlock: '未婚',
        workAge: '',
        workID: '',
        workState: '在职',
      },
      loading: false,
      total: 0,
      currentPage: 1,
      size: 10,
      dialogVisible: false,
      politicsState: [],
      nations: [],
      jobLevels: [],
      position: [],
      tiptopDegrees: ['博士', '硕士', '本科', '大专', '高中', '初中', '小学', '其他'],
    }
  },
  methods: {
    cancelSearch(){
      this.searchVisible = {
        politicId: null,
            nationId: null,
            posId: null,
            jobLevelId: null,
            engageForm: '',
            departmentId: null,
            beginDateScope:''
      }
      this.initEmps();
    },
    onSuccess() {
      this.importButtonIcon = 'el-icon-upload2';
      this.importButtonText = '导入数据';
      this.disabledUpload = false;
      this.$message.success('导入数据成功');
      this.initEmps();
    },
    onError() {
      this.importButtonIcon = 'el-icon-upload2';
      this.importButtonText = '导入数据';
      this.$message.error('导入数据失败');
      this.disabledUpload = false;
    },
    beforeUpload() {
      this.importButtonIcon = 'el-icon-loading';
      this.importButtonText = '正在导入';
      this.disabledUpload = true;
    },
    exportFile() {
      this.downloadRequest('/api/excel/export');
    },
    handleEdit(data) {
      this.title = '编辑员工';
      this.departmentName = data.department.name;
      this.emp = data;
      this.dialogVisible = true;
      this.visible = false;
    },
    handleDelete(data) {
      this.$confirm('此操作将删除员工：[ ' + data.name + ' ], 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteRequest('/api/employee/basic/' + data.id).then(resp => {
          if (resp) {
            this.initEmps();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    doAddEmp() {
      if (this.emp.id) {
        this.putRequest('/api/employee/basic/', this.emp).then(resp => {
          if (resp) {
            this.dialogVisible = false;
            this.initEmps();
          }
        })
      } else {
        this.$refs['empForm'].validate((value) => {
          if (value) {
            this.postRequest('/api/employee/basic/', this.emp).then(resp => {
              if (resp) {
                this.dialogVisible = false;
                this.initEmps();
              }
            })
          } else {
            this.$message.error("输入所有字段");
            return false;
          }
        })
      }
    },
    handleNodeClick(data) {
      this.departmentName = data.name;
      this.emp.departmentId = data.id;
      this.visible = false;
    },
    searchHandleNodeClick(data) {
      this.departmentName = data.name;
      this.searchVisible.departmentId = data.id;
      this.visible2 = false;
    },
    selectDep2() {
      this.visible2 = !this.visible;
    },
    selectDep() {
      this.visible = !this.visible;
    },
    initPosition() {
      this.getRequest('/api/employee/basic/position').then(resp => {
        if (resp) {
          this.position = resp;
        }
      })
      this.getRequest('/api/employee/basic/maxWorkId').then(resp => {
        if (resp) {
          this.emp.workID = resp.result;
        }
      })
    },
    initData() {
      if (!window.sessionStorage.getItem('politicsState')) {
        this.getRequest('/api/employee/basic/politicsState').then(resp => {
          if (resp) {
            this.politicsState = resp;
            window.sessionStorage.setItem('politicsState', JSON.stringify(resp));
          }
        })

      } else {
        this.politicsState = JSON.parse(window.sessionStorage.getItem('politicsState'));
      }

      if (!window.sessionStorage.getItem('nations')) {
        this.getRequest('/api/employee/basic/nations').then(resp => {
          if (resp) {
            this.nations = resp;
            window.sessionStorage.setItem('nations', JSON.stringify(resp));
          }
        })

      } else {
        this.nations = JSON.parse(window.sessionStorage.getItem('nations'));
      }

      if (!window.sessionStorage.getItem('jobLevels')) {
        this.getRequest('/api/employee/basic/jobLevels').then(resp => {
          if (resp) {
            this.jobLevels = resp;
            window.sessionStorage.setItem('jobLevels', JSON.stringify(resp));
          }
        })
      } else {
        this.jobLevels = JSON.parse(window.sessionStorage.getItem('jobLevels'));
      }
      if (!window.sessionStorage.getItem('department')) {
        this.getRequest('/api/employee/basic/department').then(resp => {
          if (resp) {
            this.allDeps = resp;
            window.sessionStorage.setItem('department', JSON.stringify(resp));
          }
        })
      } else {
        this.allDeps = JSON.parse(window.sessionStorage.getItem('department'));
      }

    },
    showAddEmpView() {
      // this.emp.beginDate = new Date();
      // this.emp.beginContract = new Date();
      this.title = '添加员工';
      this.departmentName = '';
      this.emp = {
        id: '',
        address: '',
        beginContract: '',
        beginDate: '',
        birthday: '',
        contractTerm: null,
        conversionTime: '',
        departmentId: null,
        email: '',
        endContract: '',
        engageForm: '',
        gender: '男',
        idCard: '',
        jobLevelId: null,
        name: '',
        nationId: 1,
        nativePlace: '',
        notWorkDate: null,
        phone: '',
        politicId: 13,
        posId: null,
        salaryId: null,
        school: '',
        specialty: '',
        tiptopDegree: '',
        wedlock: '未婚',
        workAge: '',
        workID: '',
        workState: '在职',
      };
      this.visible = false;
      this.dialogVisible = true;
      this.$refs['empForm'].resetFields();

    },
    handleClose(done) {
      this.$confirm('您填写的数据将会被清空！！确认关闭？')
          .then(_ => {
            done();
            this.initEmps();
          })
          .catch(_ => {
          });
    },
    sizeChange(size) {
      this.size = size;
      this.initEmps();
    },
    currentChange(currentPage) {
      this.currentPage = currentPage;
      this.initEmps();
    },
    initEmps(type) {
      this.loading = true;
      let url = '/api/employee/basic/?currentPage=' + this.currentPage + '&size=' + this.size;
      if (type && type == 'advance'){
        if (this.searchVisible.politicId){
          url = url + "&politicId=" + this.searchVisible.politicId;
        }
        if (this.searchVisible.departmentId){
          url = url + "&departmentId=" + this.searchVisible.departmentId;
        }
        if (this.searchVisible.nationId){
          url = url + "&nationId=" + this.searchVisible.nationId;
        }
        if (this.searchVisible.jobLevelId){
          url = url + "&jobLevelId=" + this.searchVisible.jobLevelId;
        }
        if (this.searchVisible.posId){
          url = url + "&posId=" + this.searchVisible.posId;
        }
        if (this.searchVisible.engageForm){
          url = url + "&engageForm=" + this.searchVisible.engageForm;
        }
        if (this.searchVisible.beginDateScope){
          url = url + "&beginDateScope=" + this.searchVisible.beginDateScope;
        }

      } else {
        url = url + "&name=" + this.empName;
      }

      this.getRequest(url).then(resp => {
        if (resp) {
          this.emps = resp.data;
          this.total = resp.total;
        }
        this.loading = false;
      })
    },
  },
  mounted() {
    this.initEmps();
    this.initData();
    this.initPosition();
  }

}
</script>

<style scoped>
.emp-header {
  display: flex;
  justify-content: space-between;
}

.emp-header-right {
  margin: 8px 0;

}
.bounce-enter-active {
  animation: bounce-in .5s;
}
.bounce-leave-active {
  animation: bounce-in .5s reverse;
}
@keyframes bounce-in {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

</style>